<?php

/**
 * Created by PhpStorm.
 * User: 张彪
 * Date: 2016/5/13 0013
 * Time: 上午 9:51
 */
class City_model extends Base_Model
{

    public function __construct()
    {
        $this->load->database();
    }

    public function getcitytype()
    {
        $this->db->select('c.id as cityId, c.cityName,c.countryName,c.continentName, t.id as typeId,t.name as typeName');
        $this->db->from('mod_city as c');
        $this->db->join('mod_scenic_type as t', 't.cityId = c.id', 'left');
        $query = $this->db->get()->result_array();
        $citys =array();
        if(!empty($query))
        {
            foreach ($query as $q)
            {//去除自定义景点
              if($q['typeId']!=2){
                $type = array();
                $type['typeId'] = $q['typeId'];
                $type['typeName'] = $q['typeName'];
                $q['continentName']  = $this->getname($q['continentName']);
                $q['countryName']  = $this->getname($q['countryName']);
                $c[$q['countryName']][$q['cityId']]['name'] = $this->getname($q['cityName']);
                $c[$q['countryName']][$q['cityId']]['id'] = $q['cityId'];
                $c[$q['countryName']][$q['cityId']]['tags'][] = $type;
                $citys[$q['continentName']][$q['countryName']]  = array_values($c[$q['countryName']]);
              }
            }
        }
        return $citys;
    }

    public function getcity()
    {
        $this->db->from('mod_city ');
        $query = $this->db->get()->result_array();
        $citys =array();
        if(!empty($query))
        {
            foreach ($query as $q)
            {

                $c['name'] = $this->getname($q['cityName']) ;
                $c['id'] = $q['id'];
                $q['continentName']  = $this->getname($q['continentName']);
                $q['countryName']  = $this->getname($q['countryName']);
                $citys[$q['continentName']][$q['countryName']][] = $c;
            }
        }
        return $citys;
    }

    private function getname($name)
    {
        $str = explode('|',$name);
        if(!empty($str[false]))
        {
            $name = $str[false];
        }
        return $name;

    }





}
